import threading
import time


def test():
    time.sleep(1)
    print(f"\n当前线程{threading.current_thread().name}正在执行...")


class MyThread(threading.Thread):

    def __init__(self, name):
        super().__init__()
        self.name = name

    def run(self):
        time.sleep(1)
        print(f"当前线程{threading.current_thread().name}正在执行...")


if __name__ == '__main__':

    """
        使用threading模块创建线程。
    """
    # print(f"主线程线程{threading.current_thread().name}执行开始...")
    # list = [threading.Thread(target=test) for i in range(5)]
    # for item in list:
    #     # 阻塞主线程
    #     item.start()
    # time.sleep(2)
    # print(f"主线程线程{threading.current_thread().name}执行结束...")

    print("-" * 40)

    print(f"主线程线程{threading.current_thread().name}执行开始...")
    """
    使用继承创建线程。
    """
    lst = [MyThread(name=f"线程{i}") for i in range(2)]
    for item in lst:
        item.start()
    print(f"主线程线程{threading.current_thread().name}执行结束...")



